Skip to content

fix(standards): report every storage size a standard note accepts - #3810

Merged
mmagician merged 10 commits into
nextfrom
fix-expected-storage-size
Sep 8, 2026
Merged

fix(standards): report every storage size a standard note accepts#3810
mmagician merged 10 commits into
nextfrom
fix-expected-storage-size

Conversation

@onurinanc

Copy link
Copy Markdown
Collaborator

Summary

  • Replace StandardNote::expected_num_storage_items with accepts_num_storage_items, which accepts 13 items for a private MINT note and 20 or more for a public one.
  • Narrow the variable config notes to the sizes their actions use: 1 or 3 for OWNER_CONFIG, 2 to 4 for RBAC_CONFIG, 2 or 32 for FAUCET_METADATA_CONFIG.
  • Add MIN_NUM_STORAGE_ITEMS to OwnerConfigNote, RbacConfigNote and FaucetMetadataConfigNote.
  • Pin the MINT storage item counts to the constants in asm/standards/notes/mint/.

Closes #3809.

/// `SetMaxSupply` uses this size; no size between it and [`Self::MAX_NUM_STORAGE_ITEMS`]
/// is valid. Keep in sync with `NUM_ITEMS_SET_MAX_SUPPLY` in
/// `faucet_metadata_config.masm`.
pub const MIN_NUM_STORAGE_ITEMS: usize = 2;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't necessarily have to be in this PR, but maybe it makes sense to start representing the number of storage items with a simple enum as we have very distinct variants now? Something like:

enum NumStorageItems {
    // An exact count of storage items.
    Exact(usize),
    // A range of acceptable storage item counts.
    Range { min: usize, max: usize },
}

Comment thread crates/miden-standards/src/note/mint.rs Outdated
@mmagician
mmagician requested a review from zeapoz September 8, 2026 10:49

@zeapoz zeapoz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good! I think it would be nice if we could make the Rust NUM_STORAGE_ITEMS be a NumStorageItems enum to enable some cleaner logic.

Comment thread crates/miden-standards/src/note/mod.rs Outdated
Comment on lines +190 to +197
/// Returns the number of storage items this kind of note accepts.
///
/// Several note kinds accept more than one storage size, so no single expected size can be
/// derived from the script root alone: a MINT note holds exactly
/// [`MintNote::NUM_STORAGE_ITEMS_PRIVATE`] items when it creates a private output note and at
/// least [`MintNote::MIN_NUM_STORAGE_ITEMS_PUBLIC`] when it creates a public one, and the
/// config notes size their storage per action. The returned value mirrors the sizes each note
/// script accepts; use [`NumStorageItems::accepts`] to check one against it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the number of storage items this kind of note accepts.
///
/// Several note kinds accept more than one storage size, so no single expected size can be
/// derived from the script root alone: a MINT note holds exactly
/// [`MintNote::NUM_STORAGE_ITEMS_PRIVATE`] items when it creates a private output note and at
/// least [`MintNote::MIN_NUM_STORAGE_ITEMS_PUBLIC`] when it creates a public one, and the
/// config notes size their storage per action. The returned value mirrors the sizes each note
/// script accepts; use [`NumStorageItems::accepts`] to check one against it.
/// Returns the [`NumStorageItems`] items this kind of note accepts.

Range { min: usize, max: usize },
/// The note holds a number of storage items accepted by any of these, and by none of the
/// sizes in between them.
AnyOf(&'static [NumStorageItems]),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is clever!

/// `AcceptOwnership` / `RenounceOwnership` use this size; no size between it and
/// [`Self::MAX_NUM_STORAGE_ITEMS`] is valid. Keep in sync with `NUM_ITEMS_*` in
/// `owner_config.masm`.
pub const MIN_NUM_STORAGE_ITEMS: usize = 1;

@zeapoz zeapoz Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: do we have to have these usize constants, I know that we have to sync these between MASM and Rust, but it would be nice if we could directly define e.g.:

pub const NUM_STORAGE_ITEMS: NumStorageItems = NumStorageItems::Range { min: 1, max: 3 };

I think any reasonable LLM should be able to make the link between the named MIN/MAX constants on the MASM side and this typed enum.

Self::NETWORK_ACCOUNT_CONFIG => NetworkAccountConfigNote::NUM_STORAGE_ITEMS,
Self::FEE_SPONSORSHIP => FeeSponsorshipNote::NUM_STORAGE_ITEMS,
Self::TX_FEE => TxFeeNote::NUM_STORAGE_ITEMS,
Self::P2ID => NumStorageItems::Exact(P2idNote::NUM_STORAGE_ITEMS),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// An exact count.
Self::P2ID => P2idNote::NUM_STORAGE_ITEMS,

// Any of relation with an exact count and ranged count.
Self::MINT => NumStorageItems::AnyOf(&[
                MintNote::NUM_STORAGE_ITEMS_PRIVATE,
                MintNote::NUM_STORAGE_ITEMS_PUBLIC,
            ]),

If we change the NUM_STORAGE_ITEMS constant to be a NumStorageItems, then this dispatch could be a lot cleaner, see my other comment.

@partylikeits1983 partylikeits1983 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

Only thing that needs fixing I think is the changelog.

Comment thread CHANGELOG.md Outdated
@mmagician
mmagician added this pull request to the merge queue Sep 8, 2026
Merged via the queue into next with commit ec17a44 Sep 8, 2026
19 checks passed
@mmagician
mmagician deleted the fix-expected-storage-size branch September 8, 2026 14:54
mmagician pushed a commit that referenced this pull request Sep 9, 2026
Base update, bringing in the v0.17.0-rc.4 version bump (#3837).

No conflicts, but the CHANGELOG needed a manual pass anyway: #3810's
entry auto-merged under the heading this branch renamed to
v0.17.0-rc.3, and it is not in that release. Moved to rc.4. The rc.3
section again carries exactly the published entry set.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015KNLFFu1vkaRFyybnKAYfw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expected Storage Size for MINT Notes Matches Only One of Four Valid Layouts

4 participants